#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
    vector<long long> first(26, 0);
    vector<long long> second(26, 0);
    vector<long long> third(26, 0);
    long long n;
    string pattern;
    cin >> n >> pattern;
    for (long long i = 0; i < n; i++)
    {
        long long cur = pattern[i] - 'a';
        third[cur] += second[cur];
            second[cur] += i - first[cur];
        // for(int i = 0; i < 26; i++)
        // {
        //     if(i == cur) continue;
        //     second[cur] += first[i];
        // }
        first[cur] += 1;
        // cout << "第" << i + 1 << "次更新: " << (char)(cur + 'a') << endl;
        // for (int i = 0; i < 26; i++)
        //     cout << static_cast<char>(i + 'a') << " ";
        // cout << endl;
        // for (int i = 0; i < 26; i++)
        //     cout << first[i] << " ";
        // cout << endl;
        // for (int i = 0; i < 26; i++)
        //     cout << second[i] << " ";
        // cout << endl;
        // for (int i = 0; i < 26; i++)
        //     cout << third[i] << " ";
        // cout << endl;
    }
    long long ret = 0;
    for (long long i = 0; i < 26; i++)
        ret += third[i];
    cout << ret;
    return 0;
}